package com.wanmait.myhouse.mediatorController;

import com.wanmait.myhouse.dao.MediatorFeedDAO;
import com.wanmait.myhouse.vo.MediatorFeed;
import com.wanmait.myhouse.vo.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("mediator")
public class ManagerReplyController {
    @GetMapping("managerReply")
    public String managerReply(MediatorFeed mediatorFeed, Model model , Integer pno){
        MediatorFeedDAO mediatorFeedDAO = new MediatorFeedDAO();
        Pager pager = new Pager();
        if (pno == null){
            pno = 1;
        }
        pager.setPageNO(pno);
        pager.setPageSize(4);
        int total = mediatorFeedDAO.getTotal(mediatorFeed);
        int pageCount = total / pager.getPageSize()+(total% pager.getPageSize()==0?0:1);
        pager.setPageCount(pageCount);
        model.addAttribute("pager",pager);
        List<MediatorFeed> mediatorFeedList = mediatorFeedDAO.selectByMediatorId(mediatorFeed.getMediatorId(), pager);
        model.addAttribute("feedBackList",mediatorFeedList);
        return "/mediator/managerReply";
    }
}
